package dao

import (
	"fmt"
	"go/models"
)

func AddPunishment(punishement models.Punishement) error {
	fmt.Println(punishement)
	// err := db.Table("student_message").Select("sno", "sname", "ssex", "sage", "sdept", "sedu_sys", "sregion", "spolitics", "snation").Create(&student).Error
	err := db.Table("punishment").Create(&punishement).Error
	return err
}

func DelPunishment(sno int) error {
	err := db.Table("punishment").Where("sno = ?", sno).Update("is_del", true).Error
	return err
}

func UpdatePunishment(punishement models.Punishement) error {
	sno := punishement.Sno
	err := db.Table("punishment").Where("sno = ?", sno).Updates(&punishement).Error
	return err
}

func GetPunishment(punishementParam map[string]interface{}) ([]models.Punishement, int64, error) {
	var punishmentData []models.Punishement
	page := punishementParam["page"].(int)
	pageSize := punishementParam["limit"].(int)
	searchName := punishementParam["searchName"].(string)
	var total int64
	err := db.Table("punishment").Where("sno like ? AND is_del = false", searchName+"%").Order("sno ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&punishmentData).Error
	return punishmentData, total, err
}
